﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DroneAPI
{
    class DroneControl
    {

        private static uint sequenceNumber = 1;
        private static bool interrupt = false;

        // The main control loop to send commands to the drone
        public static async void ControlLoop()
        {
            while (true)
            {
                if (interrupt)
                {
                    interrupt = false;
                    sequenceNumber = 1;
                    break;
                }

                string commandToSend = InputProcessing.NextCommand(sequenceNumber);
                await DroneConnection.SendDroneCommand(commandToSend);

                sequenceNumber++;

                await System.Threading.Tasks.Task.Delay(30);
            }
        }

        // Suspends the control loop and resets the sequence number counter
        public static void InterruptControlLoop()
        {
            interrupt = true;
        }
    }
}
